/*
 * @Author: Mr_Wei
 * @Description: 配置拦截器
 * @Date: 09:51 2019/07/01
 * @Param: http.js
 * @return:
 **/ 

import axios from "axios";
import qs from 'qs';


const server = axios.create({
    timeout: 10000  //ms
})

// 请求拦截
server.interceptors.request.use(config => {
    // if(ICookie.getItem('token')) {
    //     config.headers.token = ICookie.getItem('token')
    // }
    // if (window.localStorage.token) {
    //   config.headers.token = window.localStorage.token
    // }
    // config.withCredentials = true
    // config.crossDomain = true
    config.data = qs.stringify(config.data,{arrayFormat: 'repeat', allowDots: true})
    return config;
}, error => {
    return Promise.reject(error);
});

// 响应拦截
server.interceptors.response.use(response => {
    return Promise.reject(response.data)
}, error => {
    return Promise.reject(error)
})

export default server;